import 'package:shared_preferences/shared_preferences.dart';

class SpHelper {
  const SpHelper._();

  // static const SpHelper _instance = SpHelper._();
  // factory SpHelper() {
  //   return _instance;
  // }

  static late SharedPreferences _sharedPreferences;

  /// 必备数据的初始化操作
  ///
  /// 由于是同步操作会导致阻塞,所以应尽量减少存储容量
  static Future<void> init() async {
    _sharedPreferences = await SharedPreferences.getInstance();
  }

  static dynamic get(String key) => _sharedPreferences.get(key);

  static setInt(String key, int value) => _sharedPreferences.setInt(key, value);

  static int? getInt(String key) => _sharedPreferences.getInt(key);

  static setDouble(String key, double value) => _sharedPreferences.setDouble(key, value);

  static double? getDouble(String key) => _sharedPreferences.getDouble(key);

  static setBool(String key, bool value) => _sharedPreferences.setBool(key, value);

  static bool? getBool(String key) => _sharedPreferences.getBool(key);

  static setString(String key, String value) => _sharedPreferences.setString(key, value);

  static String? getString(String key) => _sharedPreferences.getString(key);

  static setStringList(String key, List<String> value) => _sharedPreferences.setStringList(key, value);

  static List<String>? getStringList(String key) => _sharedPreferences.getStringList(key);

  static void remove(String key) => _sharedPreferences.remove(key);

  static void clear() => _sharedPreferences.clear();
}
